package com.jtbd.controller;

import com.jtbd.constants.ResponseCodeEnum;
import com.jtbd.dto.result.ResponseBaseData;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;

@RestController
@Tag(name = "内部错误中转接口")
public class ErrorController {
    @RequestMapping(value = "/api/error", method = {RequestMethod.GET, RequestMethod.POST})
    public ResponseBaseData<String> error(HttpServletRequest request) {
        Object error = request.getAttribute("error");
        if (!ObjectUtils.isEmpty(error)) {
            return ResponseBaseData.error(ResponseCodeEnum.ERROR.getCode(), error.toString());
        }
        return ResponseBaseData.error(ResponseCodeEnum.ERROR.getCode(), "接口错误！");
    }
}
